function timeFormate(val,str){//val时间，单位秒
	if(!val){return ''}else{
		var m=parseInt(val/60);
		var s=val-m*60;
		var res='';
		if(str){
			res=str
			.replaceAll('mm',m>9?m:('0'+m))
			.replaceAll('ss',s>9?s:('0'+s))
		}else{
			res=m+'分'+s+'秒';
		};
		return res;
	};
}

function dateFormate(date,str){
	if(!date){return ''}else{
		var weekArr=['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
		var y=new Date(date).getFullYear();
		var m1=new Date(date).getMonth()+1;
		var d=new Date(date).getDate();
		var h=new Date(date).getHours();
		var m2=new Date(date).getMinutes();
		var s=new Date(date).getSeconds();
		var week=new Date(date).getDay();
		var res='';
		if(str){
			res=str
			.replaceAll('YYYY',y)
			.replaceAll('MM',m1>9?m1:('0'+m1))
			.replaceAll('DD',d>9?d:('0'+d))
			.replaceAll('hh',h>9?h:('0'+h))
			.replaceAll('mm',m2>9?m2:('0'+m2))
			.replaceAll('ss',s>9?s:('0'+s))
			.replaceAll('week',weekArr[week]);
		}else{
			res=y+'/'+(m1>9?m1:('0'+m1))+'/'+(d>9?d:('0'+d));
		};
		return res;
	};
}
function tdDateFormate(date,str){
	var dt=new Date(date.replaceAll('-','/'));
	var weekArr=['周日','周一','周二','周三','周四','周五','周六'];
	if(!dt){return ''};
	var y=new Date(date).getFullYear();
	var m=new Date(date).getMonth()+1;
	var d=new Date(date).getDate();
	var week=new Date(date).getDay();
	var res='';
	if(str){
		res=str
		.replaceAll('YYYY',y)
		.replaceAll('MM',m>9?m:('0'+m))
		.replaceAll('DD',d>9?d:('0'+d))
		.replaceAll('week',weekArr[week])
	}else{
		res=y+'/'+(m>9?m:('0'+m))+'/'+(d>9?d:('0'+d));
	};
	return res;
}

export default{
	timeFormate,dateFormate,tdDateFormate
}